<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <link href="./static/plugins/bootstrap/bootstrap.min.css" rel="stylesheet">
    <link href="./static/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="./static/css/font-awesome.min.css" rel="stylesheet">
    <link href="./static/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="./static/plugins/blueimp/blueimp-gallery.min.css" rel="stylesheet">
    <link href="./static/plugins/ladda/ladda-themeless.min.css" rel="stylesheet">
    <link href="./static/css/animate.css" rel="stylesheet">
    <link href="./static/css/style.css" rel="stylesheet">

    <script type="text/javascript" src="./static/js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="./static/plugins/bootstrap/bootstrap.min.js"></script>
</head>
<body class="fixed-sidebar no-skin-config full-height-layout">
<div id="wrapper" v-cloak>
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="sidebar-collapse">
            <ul class="nav metismenu" id="side-menu">
                <li class="nav-header">
                    <div class="dropdown profile-element">
                        <span class="img-thumb"><strong class="font-bold">{{user.company}}</strong></span>
                        <a href="javascript:">
                            <span class="clear">
                                <span class="block m-t-xs"> <strong class="font-bold">{{type[user.type]}}</strong></span>
                            </span>
                        </a>
                    </div>
                </li>
                <li>
                    <a href="/home.html"><i class="fa fa-home"></i> <span class="nav-label">个人中心</span></a>
                </li>
                <li>
                    <a href="#"><i class="fa fa-info-circle"></i> <span class="nav-label">基本信息</span><span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="user.html">个人信息</a></li>
                        <li><a href="verify.html">账号认证</a></li>
                        <li><a href="finance.html">财务明细</a></li>
                        <li v-if="user.is_root>0"><a href="employee.html">员工账号</a></li>
                        <li><a href="pwd.html">修改密码</a></li>
                        <li><a href="address.html">收货地址</a></li>
                    </ul>
                </li>
                <li v-if="user.type!=2">
                    <a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">询价</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="inquiry_list.html">询价单</a></li>
                        <li><a href="enquiry.html">我要询价</a></li>
                    </ul>
                </li>
                <li v-else class="active">
                    <a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">报价</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li class="active"><a href="inquiry_list_supply.html">未报价</a></li>
                        <li><a href="offer_sheet.html">已报价</a></li>
                    </ul>
                </li>
                <li>
                    <a href="index.html"><i class="fa fa-first-order"></i> <span class="nav-label">订单管理</span> <span class="fa arrow"></span></a>
                    <ul class="nav nav-second-level collapse">
                        <li><a href="order_list.html">订单列表</a></li>

                    </ul>
                </li>
                <li>
                    <a onclick="logout()"><i class="fa fa-sign-out"></i> <span class="nav-label">退出登录</span></a>
                </li>
            </ul>
        </div>
    </nav>
    <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <a class="navbar-minimalize minimalize-styl-2 btn btn-success" href="#"><i class="fa fa-bars"></i> </a>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li class="m-r">
                        <span class="m-r-sm text-danger font-bold welcome-message" id="nav-title">{{user.name}}&nbsp;</span><span>{{user.company}}&nbsp;{{user.zone}}</span>
                    </li>
                    <li class="dropdown m-r">
                        <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#" aria-expanded="false">
                            <i class="fa fa-bell"></i> <span class="label label-danger" v-if="msgbox.total">{{msgbox.total}}</span>
                        </a>
                        <ul class="dropdown-menu dropdown-alerts">
                            <li v-if="msgbox.daifahuo">
                                <a href="javascript:parent.document.getElementById('main').src='order_list.html?order_status=200'">
                                    <div>
                                        <i class="fa fa-envelope fa-fw"></i> 您有<strong>{{msgbox.daifahuo}}</strong>个待发货订单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daifahuo"></li>
                            <li v-if="msgbox.daifukuan">
                                <a href="javascript:parent.document.getElementById('main').src='order_list.html?order_status=100'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.daifukuan}}</strong>个待付款订单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daifukuan"></li>
                            <li v-if="msgbox.daishouhuo">
                                <a href="javascript:parent.document.getElementById('main').src='order_list.html?order_status=300'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.daishouhuo}}</strong>个订单待收货
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daishouhuo"></li>
                            <li v-if="msgbox.baojiazhong && user.type==1">
                                <a href="javascript:parent.document.getElementById('main').src='inquiry_list.html?status=100'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.baojiazhong}}</strong>个报价中询价单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.baojiazhong && user.type==1"></li>
                            <li v-if="msgbox.daibaojia">
                                <a href="javascript:parent.document.getElementById('main').src='inquiry_list_supply.html'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.daibaojia}}</strong>个待报价询价单
                                    </div>
                                </a>
                            </li>
                            <li class="divider" v-if="msgbox.daibaojia"></li>
                            <li v-if="msgbox.weitongguo">
                                <a href="javascript:parent.document.getElementById('main').src='offer_sheet.html'">
                                    <div>
                                        <i class="fa fa-twitter fa-fw"></i> 您有<strong>{{msgbox.weitongguo}}</strong>个报价未通过
                                    </div>
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li>
                        <a onclick="logout()">
                            <i class="fa fa-sign-out"></i> 安全退出
                        </a>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="row wrapper border-bottom white-bg p-h-sm">
            <div class="col-lg-10">
                <ol class="breadcrumb">
                    <li class="active">
                        <strong>报价</strong>
                    </li>
                </ol>
            </div>
        </div>

        <div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
            <div class="row">
                <div class="ibox-content m-b-sm border-bottom">
                    <div class="col-sm-1"><a href="inquiry_list_supply.html" class="btn btn-danger btn-outline btn-sm" id="back"><i class="fa fa-mail-reply-all text-5 fa-return"></i>&nbsp;返回</a></div>
                    <div class="clearfix"></div>
                </div>
            </div>

            <div class="row  border-bottom white-bg dashboard-header">
                <div class="col-md-4">
                    <h2>询价单详情</h2>
                    <small>询价单号: {{inquiry.id}}&nbsp;&nbsp;发布时间: {{inquiry.created_at}}</small>
                    <div class="ibox float-e-margins">
                        <div class="ibox-content no-borders">
                            <table class="table table-hover sumary">
                                <tbody>
                                <tr>
                                    <th>品牌</th>
                                    <td v-if="inquiry.hasOwnProperty('car_brand')">{{inquiry.car_brand.brand}}</td>
                                </tr>
                                <tr>
                                    <th>车型</th>
                                    <td>{{inquiry.car_model}}</td>
                                </tr>
                                <tr>
                                    <th>车牌号</th>
                                    <td>{{inquiry.car_number}}</td>
                                </tr>
                                <tr>
                                    <th>车架号</th>
                                    <td>{{inquiry.vin_code}}</td>
                                </tr>
                                <tr v-if="inquiry.order_type==0 && inquiry.insurer">
                                    <th>保险公司</th>
                                    <td>{{inquiry.insurer.name}} ({{inquiry.insurer.zone}})</td>
                                </tr>
                                <tr v-if="inquiry.order_type==0">
                                    <th>报案号</th>
                                    <td>{{inquiry.report_number}}</td>
                                </tr>
                                <tr v-if="inquiry.company">
                                    <th>询价公司</th>
                                    <td v-if="inquiry.order_type==1 && inquiry.insurer_id>0">{{inquiry.company.name}} ({{inquiry.company.zone}})</td>
                                    <td v-else>{{inquiry.company.name}}</td>
                                </tr>
                                <tr v-if="inquiry.members">
                                    <th>联系人</th>
                                    <td>{{inquiry.members.name}}</td>
                                </tr>
                                <tr v-if="inquiry.members">
                                    <th>联系电话</th>
                                    <td>{{inquiry.members.phone}}</td>
                                </tr>
                                </tbody>
                            </table>
                            <div class="">
                                询价备注: {{inquiry.remark}}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-10">
                    <h2>车辆图片</h2>
                    <div class="lightBoxGallery links text-left img-100">
                        <a v-for="(vo,index) in inquiry.car_photos" :href="vo.img"><img :src="vo.img"></a>
                    </div>
                </div>
                <div class="col-md-10" v-if="inquiry.form_type>0">
                    <h2>报价图片</h2>
                    <div class="lightBoxGallery links text-left img-100 bj">
                        <a v-for="(vo,index) in inquiry.inquiry_photos" :href="vo.img"><img :src="vo.img"></a>
                    </div>
                </div>
                <div class="col-md-10" v-else>
                    <h2>询价配件</h2>
                    <div class="ibox float-e-margins">
                        <div class="ibox-content no-borders">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>名称</th>
                                    <th>OE码</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr v-for="(vo,index) in inquiry.inquiry_forms">
                                    <td>{{index+1}}</td>
                                    <td>{{vo.name}}</td>
                                    <td>{{vo.oecode}}</td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row ibox-content m-t table-responsive">
                <h2>填写报价信息</h2>
                <table class="table table-hover" v-if="inquiry.form_type==0">
                    <thead>
                    <tr>
                        <th class="text-center" width="5%">编号</th>
                        <th class="text-center" width="17%">零件</th>
                        <th class="text-center">OE码</th>
                        <th v-for="(vo,index) in inquiry.inquiry_forms[0].prices" class="text-center">{{vo.quality}}</th>
                        <th class="text-center" width="23%">备注</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(vo,index) in inquiry.inquiry_forms">
                        <td style="text-align: center">{{index+1}}</td>
                        <td style="text-align: center">{{vo.name}}</td>
                        <td><input type="text" class="form-control input-sm" v-model="vo.oecode" placeholder="OE码"></td>
                        <td v-for="(vp,idx) in vo.prices"><input type="text" class="form-control input-sm" placeholder="请输入报价" v-model="vp.price"></td>
                        <td><input type="text" class="form-control input-sm" placeholder="备注信息" v-model="vo.remark"></td>
                    </tr>
                    </tbody>
                </table>
                <table class="table table-hover" v-else>
                    <thead>
                    <tr>
                        <th class="text-center" width="5%">编号</th>
                        <th class="text-center" width="17%">零件</th>
                        <th class="text-center">OE码</th>
                        <th v-for="(vo,index) in quality" class="text-center">{{vo}}</th>
                        <th class="text-center">备注</th>
                        <th class="text-center" width="5%">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(vo,index) in img_offer" :data-idx="index">
                        <td style="text-align: center">{{index+1}}</td>
                        <td style="text-align: center"><input type="text" class="form-control input-sm part-name" v-model="vo.name" placeholder="请填写零件名称"></td>
                        <td><input type="text" class="form-control input-sm" v-model="vo.oecode" placeholder="请填写OE码"></td>
                        <td v-for="(vp,idx) in vo.prices" class="text-center">
                            <input type="text" class="form-control input-sm" v-model="vp.price">
                        </td>
                        <td class="text-center"><input type="text" class="form-control input-sm" v-model="vo.remark" placeholder="备注信息"></td>
                        <td><a class="btn btn-sm btn-outline btn-danger" @click="delItem(index)"><i class="fa fa-times"></i></a></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <div class="row ibox-content">
                <div class="col-md-2 col-md-offset-4">
                    <button type="button" class="ladda-button btn btn-block btn-primary" data-style="expand-right" @click="saveQuote()">提交报价</button>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="blueimp-gallery" class="blueimp-gallery">
    <div class="slides"></div>
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
</div>
<script type="text/javascript" src="./static/plugins/toastr/toastr.min.js"></script>
<script type="text/javascript" src="./static/plugins/blueimp/jquery.blueimp-gallery.min.js"></script>
<script type="text/javascript" src="./static/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="./static/plugins/ladda/spin.min.js"></script>
<script type="text/javascript" src="./static/plugins/ladda/ladda.min.js"></script>
<script type="text/javascript" src="./static/plugins/ladda/ladda.jquery.min.js"></script>
<script type="text/javascript" src="./static/js/slimscroll.min.js"></script>
<script type="text/javascript" src="./static/js/metisMenu.js"></script>
<script type="text/javascript" src="./static/js/inspinia.js"></script>
<script type="text/javascript" src="./static/js/vue.min.js"></script>
<script type="text/javascript" src="./static/js/main.js"></script>
<script>
    //0:待发布 100:待报价 200:已选价 300:已完成 400:已取消
    var vm = new Vue({
        el: '#wrapper',
        data: {
            user: {},
            inquiry: {},
            quality: [],
            img_offer: [],
            type: {"1": "修理厂", "2": "配件商", "3": "保险公司"},
            msgbox: {},
        },
        methods: {
            getData: function (instance) {
                $.ajax({
                    type: 'POST',
                    url: api + 'user/inquiryDetail',
                    data: {id: getUrlParam('id')},
                    success: function (data) {
                        checkToken(data);
                        instance.inquiry = data.data;
                        if (data.data.form_type > 0) {
                            $.ajax({
                                type: 'POST',
                                url: api + 'index/quality',
                                success: function (data) {
                                    instance.quality = data.data;
                                    instance.addItem(instance);
                                }
                            });
                        }
                    }
                });
            },
            delItem: function (index) {
                this.img_offer.splice(index, 1);
            },
            addItem: function (instance) {
                instance = instance ? instance : vm;
                var item = {"inquiry_id": instance.inquiry.id, "name": "", "oecode": "", "prices": [], "remark": ""};
                var price;
                instance.quality.forEach(function (v, i) {
                    price = {"price": "", "quality": v};
                    item.prices.push(price);
                });
                instance.img_offer.push(item);
                setTimeout(function () {
                    $('.part-name').unbind('keyup').bind('keyup', function () {
                        var index = $(this).parents('tr').data('idx');
                        if (instance.img_offer[index].name.length && !instance.img_offer[index + 1]) {
                            instance.addItem();
                        }
                    });
                }, 50);
            },
            saveQuote: function () {
                var btn = $(event.currentTarget).ladda().ladda('start');
                var param = {
                    inquiry_id: vm.inquiry.id,
                    quotes: vm.inquiry.inquiry_forms
                };
                if (vm.inquiry.form_type > 0) {
                    if (vm.img_offer.length < 2) {
                        toastr.warning('请填写报价信息');
                        return;
                    }
                    vm.img_offer.splice(vm.img_offer.length - 1, 1);
                    param.quotes = vm.img_offer;
                }
                $.ajax({
                    type: 'POST',
                    url: api + 'provider/quoting',
                    data: param,
                    success: function (data) {
                        if (data.ret == 0) {
                            if (vm.inquiry.order_type) {
                                parent.socket.send(JSON.stringify({action: "newQuote", wsmem: data.data.wsmem, inquiry_id: data.data.inquiry_id}));
                            } else {
                                parent.socket.send(JSON.stringify({action: "pendingVerify", wsmem: data.data.wsmem, inquiry_id: data.data.inquiry_id}));
                            }
                            toastr.success('您已成功提交报价', null, {
                                timeOut: 1000,
                                onHidden: function () {
                                    btn.ladda('stop');
                                    location.href = 'inquiry_list_supply.html';
                                }
                            });
                        } else {
                            btn.ladda('stop');
                            toastr.error(data.msg);
                        }
                    }
                });
            }
        },
        created: function () {
            this.user = getItem('info');
            this.getData(this);
            var self = this;
            $.ajax({
                type: 'POST',
                url: api + 'user/msgNum',
                dataType: 'json',
                success: function (data) {
                    if (data.ret == 0) {
                        self.msgbox = data.data;
                    }
                },
            });
        },
        mounted: function () {
            setTimeout(function () {
                $('.links').on('click', function (event) {
                    event = event || window.event;
                    var target = event.target || event.srcElement,
                        link = target.src ? target.parentNode : target,
                        options = {index: link, event: event},
                        links = this.getElementsByTagName('a');
                    blueimp.Gallery(links, options);
                });
            }, 100);
        }
    });

</script>
</body>
</html>
